// Proxy 对象

const person = {
  name: 'aaa',
  age: 20
}

const personProxy = new Proxy(person, {
  get(target,property){
    return property in target ? target[property] : 'default'
    // console.log(target, property)
    // return 100
  },
  set(target, property, value){
    // 数据校验
    if(property === 'age'){
      if(!Number.isInteger(value)){
        throw new TypeError(`${value} is not an int`)
      }
    }

    target[property] = value
    // console.log(target, property, value)
  }
})

personProxy.gender = true
personProxy.age = 18
console.log(personProxy.age)
